/* eslint-disable */
import { RestClient } from 'gateio-api';
import Decimal from 'decimal.js';
import { time } from 'console';
const dayjs = require('dayjs');
const crypto = require('crypto');
// 使用芝麻官方sdk下单
const GateApi = require('gate-api');

// api的key、url等信息
export let keyInfo: any = {
  // prod: {
  //   key: '6e25823445cb2613e112035696ae49b5',
  //   secret: '05b64e61e712db516cd3b210accd4b59391bffc00f3d44c4f25784cbb8d8adba',
  // },
};

export const gateKey: any = {
  url: 'https://api.gateio.ws/api/v4',
};

// 社区版sdk
export let gateRestClient: any;
const GateConf = (key, secret) => ({
  apiKey: key,
  apiSecret: secret,
  baseUrl: gateKey.url,
});

// sd动态配置 (key, secret)
export const newGate = (key, secret) => {
  keyInfo.key = key; // 给前端打印用
  gateRestClient = new RestClient(GateConf(key, secret));
};
newGate(undefined, undefined);

// sd动态配置 (key, secret)
export const adminGate = ({ key, secret }) => {
  return new RestClient(GateConf(key, secret));
};

// 官方sdk动态配置
export let guanFangGate: any;
export const newGuanFangGate = (key, secret) => {
  const client = new GateApi.ApiClient();
  client.defaultHeaders = { 'X-Gate-Channel-Id': 'qidian' };
  client.setApiKeySecret(key, secret);
  const api = new GateApi.FuturesApi(client);
  guanFangGate = api;
  return api;
};

export const adminGuanFangGate = ({ key, secret }) => {
  return newGuanFangGate(key, secret);
};

// 使用big处理数字
export const jingDuNum = (num: number | string) => new Decimal(num);

// 获取最大时间
export const getBigTime = (t1: any, t2: any) => {
  if (t1 > t2) return t1;
  return t2;
};

// 统一返回结构：成功
export const formatSuccess1 = (data = null) => ({
  code: 10000,
  msg: 'OK',
  data,
});

export const formatSuccess = (data = null) => {
  return {
    code: 10000,
    msg: 'OK',
    data,
  };
};

// 统一返回结构：失败
export const formatError = ({ code = 10002, msg = '服务器错误', data = null }) => ({ code, msg, data });

/**
 * 统一返回结构：分页
 */
export function formatPage({ pageNum = 1, pageSize = 10, total, list = [] }) {
  return formatSuccess({
    pageNum,
    pageSize,
    total: total,
    totalPage: Math.ceil(total / pageSize),
    list,
  });
}

// 将时间转化为时间戳
export const getTimestamp = (time: string) => parseInt((new Date(time).getTime() / 1000).toString(), 10);

// 格式化数据
// 数据库等返回的数据有大量冗余的属性
export const formatData = (data: any) => JSON.parse(JSON.stringify(data));

export const getTime = () => parseInt((new Date().getTime() / 1000).toString(), 10);

export async function genSign(method, url, query_string = '', payload_string = '') {
  const key = gateKey.key;
  const secret = gateKey.secret;
  const t = getTime();
  let m = crypto
    .createHash('sha512')
    .update(payload_string || '', 'utf8')
    .digest();
  const hashed_payload = m.toString('hex');
  const s = `${method}\n${url}\n${query_string || ''}\n${hashed_payload}\n${t}`;
  const sign = crypto.createHmac('sha512', secret).update(s, 'utf8').digest('hex');
  return { KEY: key, Timestamp: t.toString(), SIGN: sign };
}

// 处理request的sign
export const handleRequestSign = async (config: any) => {
  const method = config?.method.toUpperCase();
  const paramsStr = new URLSearchParams(config?.params).toString();
  // const payload_string = JSON.stringify(config?.params);
  const res: any = await genSign(method, config?.url, paramsStr);
  return res;
};

// 往订单中添加合约信息
export async function orderAddHeyue(list: any, serve: any) {
  let res = [];
  if (!list || list?.length === 0) return res;
  res = JSON.parse(JSON.stringify(list));
  const arr: any = [...new Set(res.map((item) => item.contract))];
  const contracts: any = {};
  for (const contract of arr) {
    const contractRes: any = await serve.contract({ contract });
    contracts[contract] = contractRes.data || {};
  }
  res.forEach((item: any) => {
    item.contractInfo = contracts[item?.contract];
  });
  return res;
}

// 格式化时间为时分秒
export const formatTime = (time: any) => dayjs(new Date((time + '').length > 10 ? time : time * 1000)).format('YYYY-MM-DD HH:mm:ss');

// 计算所有仓位的盈亏
export const counetPositionYK = (list: any) => {
  if (!list || list?.length === 0) return 0;
  let sum = jingDuNum(0);
  list.forEach((item: any) => {
    const baoZhengJin = item?.leverage !== '0' ? item?.margin : item?.initial_margin; //保证金
    const ysxYingLi = item?.ysxYingKui?.pnl;
    const wsxYingli = item?.weiShiXianYingKui?.num;
    // const rowSum = jingDuSum([-1 * baoZhengJin, ysxYingLi, wsxYingli]);
    const rowSum = jingDuSum([ysxYingLi, wsxYingli]); // 不减保证金
    sum = sum.add(rowSum);
  });
  return +sum;
};

// 计算所有订单的盈亏
export const counetOrderYK = (list: any, positions: any) => {
  if (!list || list?.length === 0) return 0;
  // 获取杠杆信息
  const leverMap: any = {};
  if (positions.length > 0) {
    positions.forEach((item: any) => {
      let _lever = Number(item?.leverage);
      if (_lever === 0) _lever = Number(item?.cross_leverage_limit);
      leverMap[item?.contract] = _lever;
    });
  }
  // 计算订单盈亏
  let sum = jingDuNum(0);
  list.forEach((item: any) => {
    // 处理杠杆，如果没有则用最大杠杆
    let lever = leverMap[item?.contract] || item?.contractInfo?.leverage_max;
    const baoZhengJin = countOrderBZJ({
      price: item?.price,
      coinData: item?.contractInfo,
      size: item?.size,
      lever,
    });
    sum = sum.add(baoZhengJin);
  });
  return -sum;
};

// 计算订单的保证金
export const countOrderBZJ = ({ price, coinData, size, lever }) => {
  const newPrice = Number(price);
  const chengShu = Number(coinData?.quanto_multiplier);
  const newNum = size;
  const priceNum = newPrice * chengShu * newNum;
  const duo = priceNum / lever + priceNum * Number(coinData?.maker_fee_rate);
  const kong = priceNum / lever + priceNum * Number(coinData?.taker_fee_rate);
  return duo;
};

const aaaa = jingDuSum([-164.37999999996, -11.9249568]);
//  -176.30495679996

// 精度数字求和
export function jingDuSum(list: any[]) {
  if (!Array.isArray(list)) return 0;
  let sum = jingDuNum(0);
  for (let item of list) {
    sum = sum.add(jingDuNum(item));
  }
  return +sum;
}

/*
  计算芝麻资金流水, type类型，资金费用为啥有正有负
  即将废弃
  dnw: 转入转出
  pnl: 减仓盈亏
  fee: 交易手续费
  refr: 推荐人返佣
  fund: 资金费用
  point_dnw: 点卡转入转出
  point_fee: 点卡交易手续费
  point_refr: 点卡推荐人返佣
  bonus_offset: 体验金抵扣
*/
export const countLiuShui = (list: any, direction = 1) => {
  const tmp = {
    yingKui: 0, // 总盈亏
    ziJin: 0, // 总资金
    fee: 0, // 总手续费
    sum: 0, // 上边三者之和
  };
  if (!list || list?.length === 0) return tmp;
  let yingKuiSum = jingDuNum(0);
  let ziJinSum = jingDuNum(0);
  let feeSum = jingDuNum(0);
  list.forEach((item: any) => {
    if (['pnl'].includes(item?.type)) yingKuiSum = yingKuiSum.add(jingDuNum(item?.change));
    if (['fund'].includes(item?.type)) ziJinSum = ziJinSum.add(jingDuNum(item?.change));
    if (['fee'].includes(item?.type)) feeSum = feeSum.add(jingDuNum(item?.change));
  });
  const _yingKuiSum = +yingKuiSum * direction;
  tmp.yingKui = _yingKuiSum;
  tmp.ziJin = +ziJinSum;
  tmp.fee = +feeSum;
  tmp.sum = jingDuSum([_yingKuiSum, tmp.ziJin, tmp.fee]);
  return tmp;
};

/*
  计算可用资产
*/
export function countKeYongMondy({ positions, orders, allMoney }: any) {
  // 2.处理当前仓位
  const positionNum = counetPositionYK(positions);
  // 3.处理订单
  const orderNum = counetOrderYK(orders, positions);
  // const orderNum = 0;
  // 4.可用=资产-仓位-订单
  // const keYongNum = jingDuSum([allMoney, positionNum, orderNum]);
  const keYongNum = jingDuSum([allMoney, positionNum, orderNum]);
  // const keYongNum = 0
  const tmp: any = {
    allMoney,
    position: positionNum,
    order: orderNum,
    keYong: keYongNum,
  };
  return tmp;
}

// 计算历史收益
export function countHPositionSY(arr: any) {
  const list = arr;
  if (!list || list?.length === 0) return 0;
  let sum = 0;
  for (const item of list) {
    const { pnl, pnl_pnl, pnl_fee, pnl_fund } = item?.ysxYingKui;
    sum = jingDuSum([sum, pnl_pnl, pnl_fund, pnl_fee]);
  }
  return +sum;
}

// 处理仓位的杠杆
export function handlePositionLv(data: any) {
  let type: any = 'zhu';
  let lever = Number(data?.leverage);
  if (lever === 0) {
    // 全仓
    type = 'all';
    const allLeave = data?.cross_leverage_limit;
    const defLeave = data?.contractInfo?.cross_leverage_default;
    lever = Number(allLeave !== '0' && allLeave ? allLeave : defLeave);
  }
  return { type, lever };
}

// 获取用户的芝麻keys
export async function getZmKeys(userIds, api) {
  const users = (await api.findAll({}))?.data?.list;
  if (!users || users.length === 0) return false;
  const keys = users
    .filter((item) => userIds.includes(item?.id + ''))
    .map((item) => {
      const {
        id,
        name,
        direction,
        create_time,
        tongBuTime,
        zhima: { key, secret },
      } = item;
      return { id, name, direction, create_time, tongBuTime, key, secret };
    });
  return keys;
}

// 简化当前仓位数据
export function simplifyPosition(positions: any) {
  const list = positions.map((item) => {
    const { realised_pnl, pnl_pnl, pnl_fee, pnl_fund } = item;
    const baoZhengJin = Number(item?.leverage !== '0' ? item?.margin : item?.initial_margin);
    const obj = { baoZhengJin, realised_pnl, pnl_pnl, pnl_fee, pnl_fund };
    return obj;
  });
  return list;
}

// dayin
export function logWithLocation(message) {
  const error = new Error();
  // 解析调用栈，获取调用logWithLocation的位置信息
  const stackLines = error.stack.split('\n');
  // 跳过前两行（Error构造函数和logWithLocation函数本身的信息）
  const callingLocation = stackLines[2];
  console.log(`${message} - ${callingLocation}`);
}

// 处理已实现盈亏信息，已实现ppp
export function ysxYingKui(item: any, direction) {
  const { pnl_pnl, pnl_fee, pnl_fund } = item;
  const pnl_pnl_new = direction * pnl_pnl;
  const old_pnl_fee = pnl_fee;
  const pnl_fee_new = +jingDuNum(pnl_fee).times(jingDuNum(1));
  const pnl_new = jingDuSum([pnl_pnl_new, pnl_fund, pnl_fee_new]);
  return {
    pnl: pnl_new,
    pnl_pnl: pnl_pnl_new,
    pnl_fee: pnl_fee_new,
    pnl_fund,
    old_pnl_fee,
  };
}

// 处理未实现盈亏: 未实现ppp
export function weiShiXianYingKui(record: any, direction) {
  const bili = 0;
  const baoZhengJin = Number(record?.leverage !== '0' ? record?.margin : record?.initial_margin);
  const oldHuiBaoLv = (record?.unrealised_pnl / baoZhengJin) * direction;
  const huiBaoLv = jingDuSum([oldHuiBaoLv, bili]);
  const oldNum = record?.unrealised_pnl * direction;
  const num = +jingDuNum(Math.abs(baoZhengJin)).times(jingDuNum(huiBaoLv));
  return {
    num,
    huiBaoLv,
    oldNum,
    oldHuiBaoLv,
  };
}

// 处理开始时间和结束时间
export function formatSearchTime(startTime: any, endTime: any) {
  return {
    startTime: startTime + ' 00:00:00',
    endTime: endTime + ' 24:00:00',
  };
}

// 获取同步时间
export function getSyncTime(date = null) {
  // 同步时间-默认时同步昨天
  const tongBuTime = date ? date : dayjs().subtract(1, 'day').format('YYYY-MM-DD');
  const from = tongBuTime + ' 00:00:00';
  const to = tongBuTime + ' 24:00:00';
  return {
    from: getTimestamp(from),
    to: getTimestamp(to),
    startTime: from,
    endTime: to,
    tongBuTime,
  };
}

// 获取更新历史仓位的的时间-旧
export const getUpdateHistoryTimeOld = (users, date = null) => {
  const tongBuTime = date ? date : dayjs().subtract(1, 'day').format('YYYY-MM-DD');
  const list = users.map((item) => {
    const userIds = [item?.id + ''];
    let startTime: any = '';
    startTime = dayjs(item?.tongBuTime).add(1, 'day').format('YYYY-MM-DD 00:00:00');
    if (item?.id === 5) {
      console.log('res: 获取更新历史仓位的的时间', startTime);
    }
    if (startTime === '0') startTime = dayjs(item?.create_time).format('YYYY-MM-DD HH:mm:ss');
    const endTime = tongBuTime.split(' ')[0] + ' 24:00:00';
    const res: any = {
      tongBuTime,
      userIds,
      startTime,
      endTime,
      from: getTimestamp(startTime),
      to: getTimestamp(endTime),
    };
    if (item?.id === '5' || item?.id === 5) {
      console.log('res: 获取更新历史仓位的的时间', res);
    }
    return res;
  });
  return list;
};

// 获取更新历史仓位的的时间 , userNoTongBuTime = false
export const getUpdateHistoryTime = (users, date = null) => {
  const tongBuTime = date;
  const list = users.map((user) => {
    const userIds = [user?.id + ''];
    let userTongBuTime = user?.tongBuTime;
    // let userTongBuTime = '2025-04-10 24:00:00'; // 测试
    // console.log('用户有同步时间1: ', userTongBuTime);
    let startTime: any = '';
    if (userTongBuTime === '0') {
      // 1.没有同步时间
      startTime = dayjs(user?.create_time).format('YYYY-MM-DD HH:mm:ss');
    } else {
      // 2.有同步时间，但是没有时分秒
      if (!userTongBuTime.split(' ')[1]) userTongBuTime = userTongBuTime + ' 24:00:00';
      startTime = dayjs(userTongBuTime).add(1, 'second').format('YYYY-MM-DD HH:mm:ss');
    }
    const endTime = date;
    // if (user?.id === 5) { console.log('user:id ', user?.id, user.tongBuTime); }
    if (user?.tongBuTime === '0') startTime = dayjs(user?.create_time).format('YYYY-MM-DD HH:mm:ss');
    const res: any = {
      tongBuTime,
      userIds,
      startTime,
      endTime,
      from: getTimestamp(startTime),
      to: getTimestamp(endTime),
    };
    // if (user?.id === 5) console.log('res: p获取更新历史仓位的的时间', res);
    return res;
  });
  return list;
};

// 将历史仓位入库
export const historyPositionRuKu = async (list, positionRepository) => {
  const arr = list.map((item: any) => {
    const contractInfo = JSON.stringify({
      quanto_multiplier: item.contractInfo?.quanto_multiplier,
      taker_fee_rate: item.contractInfo?.taker_fee_rate,
    });
    const params = {
      contract: item?.contract,
      leverage: item?.leverage,
      text: item?.text,
      long_price: item?.long_price,
      pnl: item?.pnl,
      pnl_pnl: item?.pnl_pnl,
      pnl_fee: item?.pnl_fee,
      pnl_fund: item?.pnl_fund,
      accum_size: item?.accum_size,
      time: item?.time,
      short_price: item?.short_price,
      side: item?.side,
      max_size: item?.max_size,
      first_open_time: item?.first_open_time,
      userId: item?.userId,
      userName: item?.userName,
      userDirection: item?.userDirection,
      userZhiMaKey: item?.userZhiMaKey,
      userTongBuTime: item?.tongBuTime,
      price: item?.price,
      // 自定义数据
      contractInfo,
      pingCangTime: dayjs(item?.time * 1000).format('YYYY-MM-DD HH:mm:ss'),
      leverInfo: JSON.stringify(item?.leverInfo),
      ysxYingKui: JSON.stringify(item?.ysxYingKui),
    };
    return positionRepository.save(params);
  });
  const res = await Promise.allSettled(arr);
  const success = res.every((item) => item.status === 'fulfilled');
  return {
    success,
    msg: '',
  };
};

// 将同步信息添加到用户表
export const getSyncUserParams = (jiLuList, tongBuDate) => {
  const { startTime, endTime, tongBuTime } = getSyncTime(tongBuDate);
  const res = jiLuList.map((item: any) => {
    const params = {
      id: item?.userId,
      // yingKuiZhiQian: item?.yingKuiZhiQian,
      // yingKuiBenCi: item?.yingKuiBenCi,
      yingKui: item?.yingKuiAll + '',
      tongBuTime,
    };
    return params;
  });
  return res;
};

// 通过时间戳获取时间
export const getNomalTime = (num: any) => dayjs(num * 1000).format('YYYY-MM-DD HH:mm:ss');

// 处理历史仓位的时间-旧的
export const handleHistoryPositionTimeOld = ({ from, to, userCreateTime }) => {
  const createTime = dayjs(userCreateTime).format('YYYY-MM-DD HH:mm:ss');
  const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
  let _startTime = from ? getNomalTime(from) : createTime;
  let _endTime = to ? getNomalTime(to) : now;
  if (from) _startTime = getBigTime(_startTime, createTime);
  return {
    startTime: _startTime,
    endTime: _endTime,
    from: getTimestamp(_startTime),
    to: getTimestamp(_endTime),
  };
};

// 处理查询时间, 如果没有传取用户创建时间，应用于历史仓位，历史委托
export const handleSeatchTime = ({ startTime, endTime, userCreateTime }) => {
  const createTime = dayjs(userCreateTime).format('YYYY-MM-DD HH:mm:ss');
  const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
  let _startTime = startTime ? startTime + ' 00:00:00' : createTime;
  let _endTime = endTime ? endTime + ' 24:00:00' : now;
  if (startTime) _startTime = getBigTime(startTime + ' 00:00:00', createTime);
  const res = {
    startTime: _startTime,
    endTime: _endTime,
    from: getTimestamp(_startTime),
    to: getTimestamp(_endTime),
  };
  // console.log('res:处理查询时间 ', res);
  return res;
};

// export const getZhiMaPositionParams = (userData) => {
//   const { tongBuTime, create_time, id } = userData;
//   let startTime = '';
//   if (tongBuTime) {
//     startTime = dayjs(tongBuTime).add(1, 'day').format('YYYY-MM-DD 00:00:00');
//   } else {
//     startTime = dayjs(create_time).format('YYYY-MM-DD HH:mm:ss');
//   }
//   const endTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
//   return {
//     startTime,
//     endTime,
//     from: getTimestamp(startTime),
//     to: getTimestamp(endTime),
//     userIds: [id + ''],
//   };
// };

export const getZhiMaPositionParams = (userData) => {
  const { tongBuTime, create_time, id } = userData;
  let startTime = '';
  if (tongBuTime) {
    let _tongBuTime = tongBuTime;
    if (!_tongBuTime.split(' ')[1]) _tongBuTime = _tongBuTime + ' 24:00:00';
    startTime = dayjs(_tongBuTime).add(1, 'second').format('YYYY-MM-DD HH:mm:ss');
  } else {
    startTime = dayjs(create_time).format('YYYY-MM-DD HH:mm:ss');
  }
  const endTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  return {
    startTime,
    endTime,
    from: getTimestamp(startTime),
    to: getTimestamp(endTime),
    userIds: [id + ''],
  };
};

// 通过历史仓位的时间参数获取同步数据的时间
export const getSyncTimeByPosition = (positionParams) => {
  const obj = {};
  positionParams.map((item: any) => {
    const { startTime, endTime, tongBuTime } = item;
    const tem = { startTime, endTime, tongBuTime };
    obj[item.userIds[0]] = tem;
  });
  return obj;
};

// 处理做多做空方向
export const handelLSCWDirection = ({ side, userDirection }) => {
  let newSide = side === 'long' ? 'long' : 'short';
  if (userDirection === -1) newSide = side === 'long' ? 'short' : 'long';
  return newSide;
};

// 将历史委托入库
export const weiTuoRuKu = async (list, repository) => {
  const arr = list.map((item: any) => {
    const contractInfo = JSON.stringify({
      quanto_multiplier: item.contractInfo?.quanto_multiplier,
      taker_fee_rate: item.contractInfo?.taker_fee_rate,
    });
    const params = {
      // 新增
      userId: item?.userId,
      userName: item?.userName,
      userDirection: item?.userDirection,
      contractInfo: contractInfo,
      // 修改数据-开始
      gateid: item?.gateid,
      geateCreateTime: item?.geateCreateTime,
      geateUpdateTime: item?.geateUpdateTime,
      finishTimeNew: item?.finishTimeNew,
      newSize: item?.newSize,
      // 修改数据-end
      is_reduce_only: item?.is_reduce_only,
      contract: item?.contract,
      is_liq: item?.is_liq,
      is_close: item?.is_close,
      size: item?.size,
      price: item?.price,
      text: item?.text,
      status: item?.status,
      finish_as: item?.finish_as,
      left: item?.left,
      tif: item?.tif,
      fill_price: item?.fill_price,
      iceberg: item?.iceberg,
      finish_time: item?.finish_time,
      biz_info: item?.biz_info,
      amend_text: item?.amend_text,
      stp_act: item?.stp_act,
      stp_id: item?.stp_id,
      update_id: item?.update_id,
      pnl: item?.pnl,
      pnl_margin: item?.pnl_margin,
      dual_type: item?.dual_type,
    };
    return repository.save(params);
  });
  // return { arr }
  const res = await Promise.allSettled(arr);
  console.log('res: ', res);
  const success = res.every((item) => item.status === 'fulfilled');
  return { success, msg: '', res };
};

// 将成交记录入库
export const chengJiaoRuKu = async (list, repository) => {
  const arr = list.map((item: any) => {
    const contractInfo = JSON.stringify({
      quanto_multiplier: item.contractInfo?.quanto_multiplier,
      taker_fee_rate: item.contractInfo?.taker_fee_rate,
    });
    const params = {
      // 新增、修改数据-开始
      userId: item?.userId,
      userName: item?.userName,
      userDirection: item?.userDirection,
      newSize: item?.newSize,
      createTimeNew: item?.createTimeNew,
      contractInfo: contractInfo,
      // 新增、修改数据-end
      price: item?.price,
      text: item?.text,
      fee: item?.fee,
      point_fee: item?.point_fee,
      trade_id: item?.trade_id,
      contract: item?.contract,
      role: item?.role,
      order_id: item?.order_id,
      size: item?.size,
      close_size: item?.close_size,
      biz_info: item?.biz_info,
      amend_text: item?.amend_text,
    };
    return repository.save(params);
  });
  const res = await Promise.allSettled(arr);
  const success = res.every((item) => item.status === 'fulfilled');
  return { success, msg: '', res };
};

// 下单时的特殊备注，参数四为时间，参数5爆仓
export const orderText = (userId, isBaoCang = true) => {
  let txt = `t-h-${userId}-${(new Date().getTime() / 1000).toFixed(0)}`;
  if (isBaoCang) txt += `-bc`;
  return txt;
};

// 获取批量爆仓参数
export const getBaoCangParams = (list, isBaoCang = true) => {
  return list.map((item: any) => {
    const { key, secret } = item?.zhima;
    return {
      contract: item?.contract,
      text: orderText(item?.userId, isBaoCang),
      price: 0,
      size: 0,
      tif: 'ioc',
      close: true,
      stp_act: '-',
      zhima: { key, secret },
    };
  });
};

// 获取批量删除参数
export const getDeleteDataParams = (id, startTime) => ({ userIds: [id], startTime, endTime: dayjs().format('YYYY-MM-DD'), justMyData: true });

// 根据用户获取批量数据
export const getBatchData = async ({ api, userIds }) => {
  const orginlist = (await Promise.allSettled(api)).map((item: any) => item?.value?.data?.list);
  const yuanShi = {};
  userIds.map((uid, i) => {
    yuanShi[uid] = orginlist[i];
  });
  const allList = [];
  orginlist.map((item) => allList.push(...item));
  return { yuanShi, allList };
};
